# Contributor: Josip <bpisoj@gmail.com>

_realname=PyICU
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-icu" "${MINGW_PACKAGE_PREFIX}-python3-icu")
pkgver=1.9.3
pkgrel=1
pkgdesc="Python extension wrapping the ICU C++ API (mingw-w64)"
arch=('any')
license=('BSD')
url="http://pyicu.osafoundation.org/"
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
                        "${MINGW_PACKAGE_PREFIX}-python3"
                        "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
                        "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
                        "${MINGW_PACKAGE_PREFIX}-icu")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.io/packages/source/P/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1a7a96212cb3e42e8df85b9062f1f1d6e207474d44f087218fad1d4ec210fa42')

prepare() {
  cd "${srcdir}"
  cp -r ${_realname}-${pkgver} build-${CARCH}
}

build() {
  CFLAGS+=" -fpermissive"
  export PYICU_CFLAGS="-DPYICU_VER=\"${pkgver}\""
  export PYICU_LFLAGS="-L${MINGW_PREFIX}/lib"
  export PYICU_INCLUDES="${MINGW_PREFIX}/include"
  export PYICU_LIBRARIES="icuin;icuuc;icudt;icule"

  # Build python 2 module
  cd "${srcdir}/build-${CARCH}"
  ${MINGW_PREFIX}/bin/python2 setup.py build

  # Build python 3 module
  cd "${srcdir}/build-${CARCH}"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python3-icu() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-icu")

  cd "${srcdir}/build-${CARCH}"
  ${MINGW_PREFIX}/bin/python3 setup.py install \
      --prefix=${MINGW_PREFIX#\/} \
      --root="${pkgdir}" \
      --optimize=1 \
      --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-icu/COPYING"
}

package_python2-icu() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-icu")

  cd "${srcdir}/build-${CARCH}"
  ${MINGW_PREFIX}/bin/python2 setup.py install \
      --prefix=${MINGW_PREFIX#\/} \
      --root="${pkgdir}" \
      --optimize=1 \
      --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-icu/COPYING"
}

package_mingw-w64-i686-python2-icu() {
  package_python2-icu
}

package_mingw-w64-i686-python3-icu() {
  package_python3-icu
}

package_mingw-w64-x86_64-python2-icu() {
  package_python2-icu
}

package_mingw-w64-x86_64-python3-icu() {
  package_python3-icu
}
